package com.lhy.skywalking.demo.controller;

import com.alibaba.fastjson.JSON;
import com.lhy.skywalking.demo.entity.User;
import com.lhy.skywalking.demo.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/dubbo/user")
public class UserController {

    @DubboReference
    private UserService userService;

    @GetMapping("/get/{id}")
    public User get(@PathVariable("id") Long id) {
        log.info("[用户任务] 准备调用dubbo服务");
        User user = userService.findById(id);
        log.info("[用户任务] 调用dubbo服务成功，获取用户信息: {}", JSON.toJSONString(user));
        return user;
    }
}

